package com.sjtu.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * nerine
 * 2/4/2020
 */
@Configuration
public class AdminFilterConfig implements WebMvcConfigurer {

    @Autowired
    private AdminHandlerFilter adminHandlerFilter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(adminHandlerFilter);
    }

    @Bean
    public FilterRegistrationBean adminFilterRegistration(TokenCheckFilter tokenCheckFilter) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(tokenCheckFilter);
        registration.addUrlPatterns("/admin/*");
        registration.setOrder(1);
        return registration;
    }
}
